<template>
  <div class="search">
    <div class="search-top">
      <form action="/">
        <van-search
          v-model="search"
          show-action
          placeholder="请输入搜索关键词"
          @cancel="$router.back()"
          @input="onSearchInput"
          @search="onSearch"
        />
      </form>
    </div>

    <!-- 搜索结果 -->
 <div class="search-result"  v-show="search.trim().length">
        <van-cell
          :title="item.title"
          @click="searchResultTap(item.title)"
          v-for="item in searchResult"
          :key="item._id"
        ></van-cell>
      </div>
    <div class="search-main">
     
      <div class="search-main-top" >
        <div class="main-m">
          <span>搜索历史</span>
          <div class="search-main-top-r">
            <em @click="clear" style="margin-right: 5px">全部删除 </em>
            <em>完成</em>
          </div>
        </div>
        <div class="main-top-footer">
          <van-icon name="delete-o" />
        </div>
      </div>
      <div class="history" v-for="(item,index) in searchHistory" :key=item._id :to="{ path: '/searchList', query: { key_word: item } }">
        <div @click="historyTap(item)" >
          <span>{{item}}</span>
        </div>
        <div class="history-r">
          <span><van-icon @click="del(index)" name="close" /></span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import search from "./search";
export default search;
</script>

<style lang="scss" scoped>
.search {
  height: 100vh;
  background-color: rgb(245, 247, 249);
  .search-result {
    padding: 0 12px;
    padding-right: 8px;
    background-color: #fff;
  }
  .search-main {
    padding: 0 12px;
    padding-right: 8px;
    background-color: #fff;
    // line-height: 3;
    .search-main-top {
      padding: 15px 0;
      .main-m {
        display: flex;
        justify-content: space-between;
        align-items: center;

        em {
          font-style: normal;
          color: #ccc;
        }
      }
    }
    .main-top-footer {
      text-align: right;
    }
  }
  .history {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid #ccc;
    line-height: 3;
    align-items: center;

    span {
      display: block;
    }
    .history-r {
      width: 5%;
      img {
        width: 100%;
      }
    }
  }
}

.van-cell {
  padding: 0;
}
.tt-icon {
  width: 6%;
}
</style>